package com.atguigu.jdbc2;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author 798133716@qq.com
 * @create 2021-02-26 20:10
 */
public class DBPool {
    @Test
    public void test() throws SQLException {
        //创建DruidDataSource对象
        DruidDataSource druidDataSource = new DruidDataSource();
        //参数设置
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("123321");
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://localhost:3306/temp");

        DruidPooledConnection connection = druidDataSource.getConnection();
        System.out.println(connection);
    }
    @Test
    public void test1() throws Exception {
        Properties p = new Properties();
        p.load(new FileInputStream("druid.properties"));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(p);
        Connection connection = dataSource.getConnection();
        System.out.println(connection);

    }
}
